/**
 */
package gradingsystem.impl;

import gradingsystem.Grade;
import gradingsystem.GradingSchema;
import gradingsystem.GradingsystemPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Grading Schema</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link gradingsystem.impl.GradingSchemaImpl#getGrades <em>Grades</em>}</li>
 *   <li>{@link gradingsystem.impl.GradingSchemaImpl#getSelectedGrade <em>Selected Grade</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class GradingSchemaImpl extends EObjectImpl implements GradingSchema {
	/**
	 * The cached value of the '{@link #getGrades() <em>Grades</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGrades()
	 * @generated
	 * @ordered
	 */
	protected EList<Grade> grades;

	/**
	 * The cached value of the '{@link #getSelectedGrade() <em>Selected Grade</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSelectedGrade()
	 * @generated
	 * @ordered
	 */
	protected Grade selectedGrade;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GradingSchemaImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GradingsystemPackage.Literals.GRADING_SCHEMA;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Grade> getGrades() {
		if (grades == null) {
			grades = new EObjectContainmentEList<Grade>(Grade.class, this, GradingsystemPackage.GRADING_SCHEMA__GRADES);
		}
		return grades;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Grade getSelectedGrade() {
		return selectedGrade;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSelectedGrade(Grade newSelectedGrade, NotificationChain msgs) {
		Grade oldSelectedGrade = selectedGrade;
		selectedGrade = newSelectedGrade;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE, oldSelectedGrade, newSelectedGrade);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSelectedGrade(Grade newSelectedGrade) {
		if (newSelectedGrade != selectedGrade) {
			NotificationChain msgs = null;
			if (selectedGrade != null)
				msgs = ((InternalEObject)selectedGrade).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE, null, msgs);
			if (newSelectedGrade != null)
				msgs = ((InternalEObject)newSelectedGrade).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE, null, msgs);
			msgs = basicSetSelectedGrade(newSelectedGrade, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE, newSelectedGrade, newSelectedGrade));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GradingsystemPackage.GRADING_SCHEMA__GRADES:
				return ((InternalEList<?>)getGrades()).basicRemove(otherEnd, msgs);
			case GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE:
				return basicSetSelectedGrade(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GradingsystemPackage.GRADING_SCHEMA__GRADES:
				return getGrades();
			case GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE:
				return getSelectedGrade();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GradingsystemPackage.GRADING_SCHEMA__GRADES:
				getGrades().clear();
				getGrades().addAll((Collection<? extends Grade>)newValue);
				return;
			case GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE:
				setSelectedGrade((Grade)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GradingsystemPackage.GRADING_SCHEMA__GRADES:
				getGrades().clear();
				return;
			case GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE:
				setSelectedGrade((Grade)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GradingsystemPackage.GRADING_SCHEMA__GRADES:
				return grades != null && !grades.isEmpty();
			case GradingsystemPackage.GRADING_SCHEMA__SELECTED_GRADE:
				return selectedGrade != null;
		}
		return super.eIsSet(featureID);
	}

} //GradingSchemaImpl
